# -*- coding: UTF-8 -*-
#!/usr/bin/env python

import re
import datetime

import encodings
from pymongo.mongo_client import MongoClient
from Common import geturl

def get7tem():
    html = geturl('http://www.weather.com.cn/weather/101210101.shtml',{})
    rt = re.findall(r'<li class="sky skyid lv3.*?">\s\S*?<h1>(.*?)</h1>\s\S.*?<p\s.*? class="wea">(.*?)</p>\s*?<p class="tem">\s\S*?<span>(\d+)</span>/<i>(\d+).*?</i>\s\S*?</p>\s\S*?<p class="win">\s\S*?<em>\s\S*?<span title="(.*?)".*?</span>\s\S*?<span title="(.*?)".*?</span>\s\S*?</em>\s\S*?<i>(.*?)</i>',html,re.S)
    if rt:
        today = datetime.date.today()
        i = 0
        for r in rt:
            d = today + datetime.timedelta(days=i)
            strd = d.strftime('%Y%m%d')
            data = {'_id':strd, 'titleday':r[0],'wea':r[1],'temup':r[2],'temlow':r[3],'win1':r[4],'win2':r[5],'win':r[6]}
            MongoClient().contact.weather.save(data)
            i = i +1